{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 循环的应用及字符串操作"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1. reverse(s)函数把s倒过来"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南周北济'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def reverse(s):\n",
    "    r = ''\n",
    "    for i in range(len(s)-1, -1, -1):\n",
    "        r += s[i]\n",
    "    return r\n",
    "reverse('济北周南')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2. 根据指定符号和行数，打印4种直角三角形和2中等腰三角形"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*\n",
      "**\n",
      "***\n",
      "****\n",
      "*****\n",
      "******\n",
      "*******\n",
      "********\n",
      "*********\n",
      "**********\n",
      "***********\n",
      "************\n",
      "*************\n",
      "**************\n",
      "***************\n",
      " \n",
      "***************\n",
      "**************\n",
      "*************\n",
      "************\n",
      "***********\n",
      "**********\n",
      "*********\n",
      "********\n",
      "*******\n",
      "******\n",
      "*****\n",
      "****\n",
      "***\n",
      "**\n",
      "*\n",
      " \n",
      " ***************\n",
      "  **************\n",
      "   *************\n",
      "    ************\n",
      "     ***********\n",
      "      **********\n",
      "       *********\n",
      "        ********\n",
      "         *******\n",
      "          ******\n",
      "           *****\n",
      "            ****\n",
      "             ***\n",
      "              **\n",
      "               *\n",
      " \n",
      "               \n",
      "              *\n",
      "             **\n",
      "            ***\n",
      "           ****\n",
      "          *****\n",
      "         ******\n",
      "        *******\n",
      "       ********\n",
      "      *********\n",
      "     **********\n",
      "    ***********\n",
      "   ************\n",
      "  *************\n",
      " **************\n",
      " \n",
      "               \n",
      "               *\n",
      "              **\n",
      "              ***\n",
      "             ****\n",
      "             *****\n",
      "            ******\n",
      "            *******\n",
      "           ********\n",
      "           *********\n",
      "          **********\n",
      "          ***********\n",
      "         ************\n",
      "         *************\n",
      "        **************\n",
      " \n",
      "***************\n",
      " **************\n",
      " *************\n",
      "  ************\n",
      "  ***********\n",
      "   **********\n",
      "   *********\n",
      "    ********\n",
      "    *******\n",
      "     ******\n",
      "     *****\n",
      "      ****\n",
      "      ***\n",
      "       **\n",
      "       *\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "def trangle(c, ls):\n",
    "    for i in range(ls):\n",
    "        t = ''\n",
    "        for j in range(i+1):\n",
    "            t += c\n",
    "        print(t)\n",
    "    print(' ')\n",
    "    for i in range(ls):\n",
    "        t = ''\n",
    "        for j in range(ls, i, -1):\n",
    "            t += c\n",
    "        print(t)\n",
    "    print(' ')\n",
    "    for i in range(ls):\n",
    "        t = ''\n",
    "        for j in range(i+1):\n",
    "            t += ' '\n",
    "        for j in range(ls, i, -1):\n",
    "            t += c\n",
    "        print(t)\n",
    "    print(' ')\n",
    "    for i in range(ls):\n",
    "        t = ''\n",
    "        for j in range(ls, i, -1):\n",
    "            t += ' '\n",
    "        for j in range(i):\n",
    "            t += c\n",
    "        print(t)\n",
    "    print(' ')\n",
    "    for i in range(ls):\n",
    "        t = ''\n",
    "        for j in range(ls, int(i/2), -1):\n",
    "            t += ' '\n",
    "        for j in range(i):\n",
    "            t += c\n",
    "        print(t)\n",
    "    print(' ')\n",
    "    for i in range(ls):\n",
    "        t = ''\n",
    "        for j in range(int((i+1)/2)):\n",
    "            t += ' '\n",
    "        for j in range(ls, i, -1):\n",
    "            t += c\n",
    "        print(t)\n",
    "trangle('*', 15)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
